import { game, ui, _status, ai, lib, get } from "../../../../noname.js";
import { swTool } from "../../main/swTool.js";
import { MAIN } from "./config/main.js";
export const type = "mode";
/**
 * @type { () => importModeConfig }
 */
export const langrensha = {
	name: "langrensha",
	startBefore: function () {
		_status.extensionMode = langrensha
	},
	onreinit: function () {
		game.createInfoUI();//创建信息栏
	},
	start() {
		"step 0"
		if (!_status.connectMode) {
			alert('目前仅联机模式可玩');
			game.exit();
			event.finish();
		}
		//TODO:
		_status.mode = get.config("langrensha_mode");
		event.replacePile = function () {
			var list = ["shengdong", "qijia", "caomu", "jinchan", "zengbin", "fulei", "qibaodao", "zhungangshuo", "lanyinjia"];
			var map = {
				shunshou: "shengdong",
				jiedao: "qijia",
				bingliang: "caomu",
				wuxie: "jinchan",
				wuzhong: "zengbin",
				wugu: "zengbin",
				shandian: "fulei",
				qinggang: "qibaodao",
				qinglong: "zhungangshuo",
				bagua: "lanyinjia",
			};
			for (var i = 0; i < lib.card.list.length; i++) {
				var name = lib.card.list[i][2];
				if (list.includes(name)) {
					lib.card.list.splice(i--, 1);
				} else if (map[name]) {
					lib.card.list[i][2] = map[name];
					lib.card.list[i]._replaced = true;
				}
			}
		};
		"step 1"
		game.waitForPlayer(function () {
			lib.configOL.number = lib.configOL.player_number;
		});
		"step 2"
		if (_status.connectMode) {
			_status.mode = lib.configOL.langrensha_mode;
			if (_status.mode == "normal") {
				//lib.configOL.number = 8;
				//event.replacePile()
			}
			else if (_status.mode == "wuxianhuoli") {
				//lib.configOL.number = 8;
				//event.replacePile()
			}
			else {
				//lib.configOL.number = 8;
				//event.replacePile()
			}
			if (lib.configOL.number < 2) {
				lib.configOL.number = 2;
			}
		} else {
			//TODO:非联机模式逻辑
		}
		"step 3"
		
		"step 4"
		game.randomMapOL();
		"step 5"
		for (var i = 0; i < game.players.length; i++) {
			game.players[i].ai.shown = 0;//ai暴漏程度
		}
		game.broadcastAll(() => { game.createInfoUI() })
		game.syncState();//此处有选将逻辑

		_status.firstAct = game.players.randomGet()
		swTool.setPlayersSeat(_status.firstAct)
		event.trigger("gameStart");
		"step 6"
		var players = get.players(lib.sort.position);
		var info = [];
		for (var i = 0; i < players.length; i++) {
			var ifo = {
				name: players[i].name1,
				name2: players[i].name2,
				identity: players[i].identity,
				nickname: players[i].node.nameol.innerHTML,
			};
			info.push(ifo);
		}
		_status.videoInited = true;
		game.addVideo("init", null, info);
		"step 7"
		event.beginner = _status.firstAct2 || _status.firstAct || game.boss || game.me;
		game.gameDraw(event.beginner, function (player) {
			return 4;
		});
		//TODO: 判断非联机
		//手气卡
		if (_status.connectMode && lib.configOL.change_card) game.replaceHandcards(game.players.slice(0));
		"step 8";
		game.phaseLoop(event.beginner);
	},
	chooseMode() {//初始化游戏完成，分配选将逻辑
		const mode = _status.mode.slice(0, 1).toUpperCase() + _status.mode.slice(1);//首字母大写
		if (typeof game['chooseCharacter' + mode + 'OL'] === 'function') {//存在对应的选择角色逻辑就跳转
			game['chooseCharacter' + mode + 'OL']()
			return;
		}
		//反之用默认的
		const next = game.createEvent('chooseCharacter');
		next.set('mode', mode)
		//TODO:添加默认的选择角色逻辑
		next.setContent("Default");
		return next
	},
	modeConfig() {

		game.chooseCharacterNormalOL = function () {
			_status.style = { identityHTML:
				`
				.player .identity[data-color="yvyanjia"] {
				text-shadow: rgba(148, 0, 211, 1) 0 0 2px,
				rgba(148, 0, 211, 1) 0 0 5px,
				rgba(148, 0, 211, 1) 0 0 10px,
				rgba(148, 0, 211, 1) 0 0 15px,
				black 0 0 1px;
				}	
				
				.player .identity[data-color="lieren"] {
				text-shadow: rgba(102, 204, 102, 1) 0 0 2px, 
				rgba(102, 204, 102, 1) 0 0 5px,
				rgba(102, 204, 102, 1) 0 0 10px,
				rgba(102, 204, 102, 1) 0 0 15px,
				black 0 0 1px;
				}
				
				.player .identity[data-color="pingmin"] {
				text-shadow: black 0 0 1px, 
				rgba(255, 225, 100, 1) 0 0 2px, 
				rgba(255, 225, 100, 1) 0 0 5px,
				rgba(255, 225, 100, 1) 0 0 10px, 
				rgba(255, 225, 100, 1) 0 0 15px;
				}
				
				.player .identity[data-color="lang"],
				.player .identity[data-color="yin_lang"] {
				text-shadow: black 0 0 1px,
				rgba(191, 0, 0, 1) 0 0 2px,
				rgba(191, 0, 0, 1) 0 0 5px,
				rgba(191, 0, 0, 1) 0 0 10px,
				rgba(191, 0, 0, 1) 0 0 15px;
				}
				`
			}
			game.broadcastAll((innerHTML) => {
				const style = document.createElement('style')
				style.innerHTML = innerHTML
				document.head.appendChild(style)
			},  _status.style.identityHTML)

			const next = game.createEvent('chooseCharacter')
			next.setContent(async event => {
				var playersAll = game.players
				var identityList = ["lang", "pingmin", "pingmin", "yvyanjia", "lang", "pingmin", "yin_lang", "lieren"].splice(0, playersAll.length);
				identityList.randomSort();

				for (let i = 0; i < playersAll.length; i++) {
					playersAll[i].identity = identityList[i];
					playersAll[i].setIdentity("cai");
					playersAll[i].node.identity.classList.add("guessing");
					playersAll[i].identityShown = false;
					//此处可以记录一下特殊的身份
				}
				game.me.setIdentity();
				game.me.node.identity.classList.remove("guessing");
				ui.arena.classList.add("choose-character");
				// if (game.me.special_identity) {
				// 	game.me.node.identity.firstChild.innerHTML = get.translation(game.me.special_identity + "_bg");
				// }
				for (var i = 0; i < playersAll.length; i++) {
					playersAll[i].send(
						function (me, identity) {
							for (var i in lib.playerOL) {
								lib.playerOL[i].setIdentity("cai");
								lib.playerOL[i].node.identity.classList.add("guessing");
							}
							me.setIdentity(identity);
							me.node.identity.classList.remove("guessing");
							ui.arena.classList.add("choose-character");
						},
						playersAll[i],
						playersAll[i].identity
					);
				}

				var list;
				var list2 = [];
				var list3 = [];
				var list4 = [];
				event.list = [];
				event.list2 = [];

				var libCharacter = {};
				for (var i = 0; i < lib.configOL.characterPack.length; i++) {
					var pack = lib.characterPack[lib.configOL.characterPack[i]];
					for (var j in pack) {
						// if(j=='zuoci') continue;
						if (lib.character[j]) libCharacter[j] = lib.character[j];
					}
				}
				for (i in lib.characterReplace) {
					var ix = lib.characterReplace[i];
					for (var j = 0; j < ix.length; j++) {
						if (!libCharacter[ix[j]] || lib.filter.characterDisabled(ix[j])) ix.splice(j--, 1);
					}
					if (ix.length) {
						event.list.push(i);
						event.list2.push(i);
						list4.addArray(ix);
						var bool = false;
						for (var j of ix) {
							if (libCharacter[j].isZhugong) {
								bool = true;
								break;
							}
						}
						(bool ? list2 : list3).push(i);
					}
				}
				game.broadcast(function (list) {
					for (var i in lib.characterReplace) {
						var ix = lib.characterReplace[i];
						for (var j = 0; j < ix.length; j++) {
							if (!list.includes(ix[j])) ix.splice(j--, 1);
						}
					}
				}, list4);
				for (i in libCharacter) {
					if (list4.includes(i)) continue;
					if (lib.filter.characterDisabled(i, libCharacter)) continue;
					event.list.push(i);
					event.list2.push(i);
					list4.push(i);
					if (libCharacter[i].isZhugong) {
						list2.push(i);
					} else {
						list3.push(i);
					}
				}
				_status.characterlist = list4.slice(0);

				var chooseList = [];
				var selectButton = lib.configOL.double_character ? 2 : 1;
				var listNum = swTool.getSelect()

				for (let i = 0; i < playersAll.length; i++) {
					const identity = playersAll[i].identity;
					let str = "狼人三国杀：请选择你的角色。Ciallo～(∠・ω< )⌒☆" + "（" + get.translation(`${identity}2`) + "）"
					chooseList.push([playersAll[i], [str, [event.list.randomRemove(listNum), "characterx"]], selectButton, true]);
				}
				var result =  await game.me.chooseButtonOL(chooseList, function (player, result) {
					if (game.online || player == game.me) player.init(result.links[0], result.links[1]);
				}).forResult();

				for (let i in result) {
					if (result[i] && result[i].links) {
						for (var j = 0; j < result[i].links.length; j++) {
							event.list2.remove(get.sourceCharacter(result[i].links[j]));
						}
					}
				}
				for (let i in result) {
					if (result[i] == "ai") {
						result[i] = event.list2.randomRemove(selectButton);
						for (var j = 0; j < result[i].length; j++) {
							var listx = lib.characterReplace[result[i][j]];
							if (listx && listx.length) result[i][j] = listx.randomGet();
						}
					} else {
						result[i] = result[i].links;
					}
					if (get.is.double(result[i][0]) || (lib.character[result[i][0]] && (lib.character[result[i][0]].group == "shen" || lib.character[result[i][0]].group == "western") && !lib.character[result[i][0]].hasHiddenSkill)) shen.push(lib.playerOL[i]);
				}
				var shen = [];
				var result2 = {}
				if (shen.length) {
					var list = ["wei", "shu", "wu", "qun", "jin", "key"];
					for (var i = 0; i < list.length; i++) {
						if (!lib.group.includes(list[i])) list.splice(i--, 1);
						else list[i] = ["", "", "group_" + list[i]];
					}
					for (var i = 0; i < shen.length; i++) {
						if (get.is.double(result[shen[i].playerid][0])) {
							shen[i]._groupChosen = "double";
							shen[i] = [
								shen[i],
								[
									"请选择你的势力",
									[
										get.is.double(result[shen[i].playerid][0], true).map(function (i) {
											return ["", "", "group_" + i];
										}),
										"vcard",
									],
								],
								1,
								true,
							];
						} else {
							shen[i]._groupChosen = "kami";
							shen[i] = [shen[i], ["请选择你的势力", [list, "vcard"]], 1, true];
						}
					}
					result2 = await game.me
						.chooseButtonOL(shen, function (player, result) {
							if (player == game.me) player.changeGroup(result.links[0][2].slice(6), false, false);
						})
						.set("switchToAuto", function () {
							_status.event.result = "ai";
						})
						.set("processAI", function () {
							return {
								bool: true,
								links: [_status.event.dialog.buttons.randomGet().link],
							};
						}).forResult();
				}

				for (var i in result2) {
					if (result2[i] && result2[i].links) result2[i] = result2[i].links[0][2].slice(6);
					else if (result2[i] == "ai")
						result2[i] = (function () {
							var player = lib.playerOL[i];
							var list = ["wei", "shu", "wu", "qun", "jin", "key"];
							for (var ix = 0; ix < list.length; ix++) {
								if (!lib.group.includes(list[ix])) list.splice(ix--, 1);
							}
							return list.randomGet();
						})();
				}

				game.broadcastAll(
					function (result, result2) {
						for (var i in result) {
							if (!lib.playerOL[i].name) {
								lib.playerOL[i].init(result[i][0], result[i][1]);
							}
							if (result2[i] && result2[i].length) lib.playerOL[i].changeGroup(result2[i], false, false);
						}
					},
					result,
					result2
				);

				for (var i = 0; i < game.players.length; i++) {
					_status.characterlist.remove(game.players[i].name);
					_status.characterlist.remove(game.players[i].name1);
					_status.characterlist.remove(game.players[i].name2);
				}


				var globalSkillList = [];
				for (var i = 0; i < globalSkillList.length; i++) {
					game.addGlobalSkill(globalSkillList[i]);
				}

				//观战和重连同步
				_status.reloadResource = (characters, HTML) => {
					for (const c in characters) {
						const { name, character, info } = characters[c]
						//if (lp.includes(character)) info.skills.push('sw_getSkill')
						lib.character[character] = info
						if (name) {
							lib.translate[character] = name
						}
					}
					const style = document.createElement('style')
					style.innerHTML = HTML.identityHTML
					document.head.appendChild(style)
				}

				game.broadcastAll(() => {
					setTimeout(function () {
						ui.arena.classList.remove('choose-character');
					}, 500);
				})
			})

		}

	},
	game: {
		//checkResult: function () {
		//	const bd = game.dead.filter((p) => p.boss);
		//	const pd = game.dead.filter((p) => !p.boss);
		//	if (bd.length >= _status.bn) {
		//		game.me.boss ? game.over(false) : game.over(true);
		//	} else if (pd.length >= 3) {
		//		game.me.boss ? game.over(true) : game.over(false);
		//	}
		//},
		getIdentityList: function (player) {
			if (player.identityShown) return;
			if (player == game.me) return;
			return {
				lang: "狼",
				yin_lang: "隐狼",
				pingmin: "民",
				yvyanjia: "预",
				lieren: "猎",
				enemy: "敌",
				friend: "友",
				cai: "猜",
			};
		},
		getIdentityList2: function (list) {
			for (var i in list) {
				switch (i) {
					case "lang":
						list[i] = "狼人";
						break;
					case "yin_lang":
						list[i] = "隐狼";
						break;
					case "pingmin":
						list[i] = "平民";
						break;
					case "yvyanjia":
						list[i] = "预言";
						break;
					case "lieren":
						list[i] = "猎人";
						break;
					case "enemy":
						list[i] = "敌方";
						break;
					case "friend":
						list[i] = "友方";
						break;
				}
			}
		},
		showIdentity: function (me) {
			for (var i = 0; i < game.players.length; i++) {
				game.players[i].node.identity.classList.remove("guessing");
				game.players[i].identityShown = true;
				game.players[i].ai.shown = 1;
				game.players[i].setIdentity(game.players[i].identity);
			}
			if (_status.clickingidentity) {
				for (var i = 0; i < _status.clickingidentity[1].length; i++) {
					_status.clickingidentity[1][i].delete();
					_status.clickingidentity[1][i].style.transform = "";
				}
				delete _status.clickingidentity;
			}
		},
		createTip: function (text) {
			const clog = ui.create.div('div', '.olskilllog', text, ui.arena)
			clog.css({
				left: "50%",
				transform: "translateX(-50%)",
				zIndex: "100",
				fontSize: "20px",
				backgroundColor: "rgba(0,0,0,.3)",
				padding: "10px",
				top: "25%",
				borderRadius: "5px",
				textShadow: "1px 1px black"
			})
			setTimeout(() => {
				clog.style.opacity = '0'
			}, 4000)
			setTimeout(() => {
				clog.remove()
			}, 6000)
			return clog
		},
		addNewPlayer: async function (name, position = undefined, identity = "zhong", side = null, animation = "zoominanim") {//此处的位置是相对于主公的位置，正数表示右边，负数表示左边,0表示主公左边1个（即在主公的位置，把主公往后推了一个）
			let players = game.players.concat(game.dead);
			let playerCnt = players.length;//总人数

			if(position === undefined) position = Math.floor(Math.random() * playerCnt) + 1

			game.addVideo("addNewPlayer", null, [position, name, animation]);

			game.broadcastAll((id, num, players, character, pos, identity, side) => {
				character = Array.isArray(character) ? character[0] : character;

				ui.arena.setNumber(num + 1);//设置多出一个位置

				if (game.zhu != null) {
					pos = (parseInt(game.zhu.dataset.position) + parseInt(pos) + parseInt(num * num)) % parseInt(num);//计算对于每个人视角下新增随从的相对位置
				}
				if (pos == 0) pos = num;

				players.forEach(value => {
					if (parseInt(value.dataset.position) >= pos) value.dataset.position = parseInt(value.dataset.position) + 1;//将新增随从后面的人位置+1
				});

				let fellow = ui.create.player();
				game.zhuFellow = fellow;
				fellow.playerid = id;
				game.playerMap[fellow.playerid] = fellow;
				lib.playerOL[fellow.playerid] = fellow;
				fellow.dataset.position = pos || playerCnt - 1;

				game.players.push(fellow);
				game.arrangePlayers();
				ui.arena.appendChild(fellow);
				//console.log(game.players);

				if (character) fellow.init(character);

				fellow.side = side;
				fellow.identity = identity;
				fellow.setIdentity(identity);
				fellow.identityShown = true;

				//game.addVideo('init', null, game.players.map(p => {
				//	return {
				//		name: p.name1,
				//		name2: p.name2,
				//		identity: (p === game.me || p === game.zhu) ? p.identity : 'cai'
				//	}
				//}))

				//game.addVideo("setIdentity", fellow, "zhong");
			}, get.id(), playerCnt, players, name, position, identity, side);

			game.zhuFellow.directgain(get.cards(4));
			await game.delay(1)
			return game.zhuFellow
		},

		removePlayer: function (player) {
			let players = game.players.concat(game.dead);
			let playerCnt = players.length - 1;//随从后的总人数

			game.broadcastAll((num, players, diePlayer) => {
				ui.arena.setNumber(num);//设置多出一个位置

				players.forEach(value => {
					if (parseInt(value.dataset.position) > diePlayer.dataset.position) value.dataset.position = parseInt(value.dataset.position) - 1;//将新增随从后面的人位置+1
				});


				game.players.remove(diePlayer);
				game.dead.remove(diePlayer);
				game.arrangePlayers();
				delete game.playerMap[diePlayer.playerid];
				delete lib.playerOL[diePlayer.playerid];
				diePlayer.delete();

			}, playerCnt, game.players.concat(game.dead), player);
			//await game.delay(1)
		},

		refreshInfo: function () {
			game.broadcast((info) => {
				_status.gameInfomation = info;
			}, _status.gameInfomation)
		},

		setGameInfo: function(name, content){
			_status.gameInfomation[name] = content
			game.refreshInfo()
		},

		getRoomInfo: function (uiintro) {
				uiintro.add('<div class="text chat">游戏模式：' + (lib.configOL.langrensha_mode == "normal" ? "标准模式" : "无限火力"));
				uiintro.add('<div class="text chat">火速加群体验最新扩展！');
				/*
				uiintro.add('<div class="text chat">双将模式：' + (lib.configOL.double_character ? "开启" : "关闭"));
				if (lib.configOL.identity_mode != "zhong") {
					if (lib.configOL.identity_mode == "stratagem") {
						uiintro.add('<div class="text chat">首轮强化：' + (lib.configOL.round_one_use_fury ? "开启" : "关闭"));
					} else if (lib.configOL.identity_mode != "purple") {
						uiintro.add('<div class="text chat">双内奸：' + (lib.configOL.double_nei ? "开启" : "关闭"));
						if (lib.configOL.identity_mode != "stratagem") {
							uiintro.add(
								`<div class="text chat">加强主公：${(() => {
									switch (lib.configOL.enhance_zhu) {
										case "sixiang":
											return "四象标记";
										case "specific":
											return "专属技能";
										default:
											return "关闭";
									}
								})()}`
							);
							uiintro.add('<div class="text chat">平民身份：' + (lib.configOL.enable_commoner ? "开启" : "关闭"));
						}
						uiintro.add('<div class="text chat">年机制：' + (lib.configOL.enable_year_limit ? "开启" : "关闭"));
					}
				} else {
					uiintro.add('<div class="text chat">卡牌替换：' + (lib.configOL.zhong_card ? "开启" : "关闭"));
				}
				var last = uiintro.add('<div class="text chat">出牌时限：' + lib.configOL.choose_timeout + "秒");
				if (lib.configOL.banned.length) {
					last = uiintro.add('<div class="text chat">禁用武将：' + get.translation(lib.configOL.banned));
				}
				if (lib.configOL.bannedcards.length) {
					last = uiintro.add('<div class="text chat">禁用卡牌：' + get.translation(lib.configOL.bannedcards));
				}
				*/
				//last.style.paddingBottom = "8px";
			},
		createInfoUI: function () {
			if (!ui.gameRule) {
				ui.gameRule = ui.create.system("游戏规则", null, true, true);
			}
			lib.setPopped(
				ui.gameRule,
				function () {
					var uiintro = ui.create.dialog("hidden");
					uiintro.add("游戏规则");
					uiintro.add(`<div class="text center">暂时还没写哦</div>`);

					uiintro.add(ui.create.div(".placeholder.slim"));
					return uiintro;
				},
				180
			);
		},

	},
	element: {
		player: {
			$dieAfter: function () {
				if (_status.video) return;
				if (!this.node.dieidentity) {
					var str;
					if (this.special_identity) {
						str = get.translation(this.special_identity);
					} else {
						//str = get.translation(this.identity + "2");
						str = "";
					}
					var node = ui.create.div(".damage.dieidentity", str, this);
					if (str == "野心家") {
						node.style.fontSize = "40px";
					}
					ui.refresh(node);
					node.style.opacity = 1;
					this.node.dieidentity = node;
				}
				var trans = this.style.transform;
				if (trans) {
					if (trans.indexOf("rotateY") != -1) {
						this.node.dieidentity.style.transform = "rotateY(180deg)";
					} else if (trans.indexOf("rotateX") != -1) {
						this.node.dieidentity.style.transform = "rotateX(180deg)";
					} else {
						this.node.dieidentity.style.transform = "";
					}
				} else {
					this.node.dieidentity.style.transform = "";
				}
			},
			dieAfter: function (source) {
				if (get.population("fan") == 0) {
					if (lib.configOL.hemengaozhan_reviveMode && lib.configOL.hemengaozhan_reviveMode == true && get.gameInfo(1) > 0) {
						// var next = game.createEvent("hmaz_revivePlayer", false);
						// next.setContent("revivePlayer");
					}
					else game.over(false)
				}
				return
			},
			dieAfter2: function (source) {
				if (this === game.zhu) {
					var next = game.createEvent("hmaz_clearStates", false);
					next.setContent("clearStates");

					var next = game.createEvent("hmaz_revivePlayer", false);
					next.setContent("revivePlayer");

					var next = game.createEvent("hmaz_gainPassReward", false);
					next.setContent("gainPassReward");

					var next = game.createEvent('hmaz_spawnChest');
					next.setContent("spawnChest");

					var next = game.createEvent("hmaz_nextBoss", false);
					next.setContent("nextBoss");
				}
				else if(lib.character && ((this.name1 && lib.character[this.name1].dieClear) || (this.name2 && lib.character[this.name2].dieClear))) {
					game.removePlayer(this)
				}
				else if(this.identity == "fan"){
					if (lib.configOL.hemengaozhan_reviveMode && lib.configOL.hemengaozhan_reviveMode == true && get.gameInfo(1) > 0) {
						var next = game.createEvent("hmaz_revivePlayer", false);
						next.setContent("revivePlayer");
					}
				}
			},
			showIdentity: function () {
				this.node.identity.classList.remove("guessing");
				this.identityShown = true;
				this.ai.shown = 1;
				this.setIdentity();
				if (_status.clickingidentity) {
					for (var i = 0; i < _status.clickingidentity[1].length; i++) {
						_status.clickingidentity[1][i].delete();
						_status.clickingidentity[1][i].style.transform = "";
					}
					delete _status.clickingidentity;
				}
			},
			insightInto: function (target) {
				var next = game.createEvent("stratagemInsight");
				next.player = this;
				next.target = target;
				next.setContent("stratagemInsight");
				return next;
			},
			setModeState2: function(info) {
				if (!game.getIdentityList && info.identityNode) {
					player.node.identity.innerHTML = info.identityNode[0];
					player.node.identity.dataset.color = info.identityNode[1];
				} else if (player == game.me || player.identityShown || observe) {
					player.setIdentity();
					player.forceShown = true;
				} else {
					player.setIdentity("cai");
				}
				if (!lib.configOL.observe_handcard && (lib.configOL.mode == "identity" || lib.configOL.mode == "guozhan")) {
					if (observe && !player.identityShown) {
						player.setIdentity("cai");
						player.forceShown = false;
					}
				}
			},
		},
		content: {
			stratagemInsight: () => {
				"step 0";
				game.log(player, "洞察了", target, "与其的阵营关系");
				"step 1";
				var storage = player.storage;
				if (!storage.zhibi) storage.zhibi = [];
				var zhibi = storage.zhibi;
				if (!zhibi.includes(target)) zhibi.push(target);
				var insightResult = (event.insightResult = get.insightResult(player, target));
				event.videoId = lib.status.videoId++;
				var send = (clientTarget, clientInsightResult, id) => {
					var classList = clientTarget.classList,
						nonStratagemInsightFlashing = classList.contains("flash-animation-iteration-count-infinite");
					if (nonStratagemInsightFlashing) clientTarget.nonStratagemInsightFlashing = true;
					else classList.add("flash-animation-iteration-count-infinite");
					var identity = get.translation(`${clientInsightResult}2`);
					clientTarget.prompt(identity, clientInsightResult);
					var dialog = ui.create.dialog(`${get.translation(clientTarget)}是${identity}<br>`, "forcebutton");
					ui.create.spinningIdentityCard(clientInsightResult, dialog);
					var control = ui.create.control("ok", () => {
						dialog.close();
						control.close();
						_status.imchoosing = false;
						_status.event._result = {
							bool: true,
						};
						game.resume();
					});
					dialog.videoId = id;
					game.pause();
					game.countChoose();
				};
				game.broadcastAll(
					(clientPlayer, clientTarget, id) => {
						if (clientPlayer != game.me) ui.create.dialog(`${get.translation(clientPlayer)}正在洞察${get.translation(clientTarget)}的阵营...<br>`).videoId = id;
					},
					player,
					target,
					event.videoId
				);
				if (event.isMine()) send(target, insightResult, event.videoId);
				else if (event.isOnline()) {
					player.send(send, target, insightResult, event.videoId);
					player.wait();
					game.pause();
				}
				"step 2";
				game.broadcastAll("closeDialog", event.videoId);
				if (!_status.connectMode && get.config("auto_mark_identity") && !target.node.identity.firstChild.innerHTML.length)
					game.broadcastAll(
						(clientPlayer, clientTarget, insightResult) => {
							if (clientPlayer.isUnderControl(true)) clientTarget.setIdentity(insightResult);
						},
						player,
						target,
						event.insightResult
					);
				var afterInsight = clientTarget => {
					clientTarget.unprompt();
					if (clientTarget.nonStratagemInsightFlashing) {
						delete clientTarget.nonStratagemInsightFlashing;
						return;
					}
					var classList = clientTarget.classList;
					if (classList.contains("flash-animation-iteration-count-infinite")) classList.remove("flash-animation-iteration-count-infinite");
				};
				if (event.isMine()) afterInsight(target);
				else if (event.isOnline()) player.send(afterInsight, target);
			},
		},
	},
	ai: {

	},
	ui: {

	},
	get: {
		//attitude: function (from, to) {
		//	if (from.boss === to.boss) return 10;
		//	return -10;
		//},
		gameInfo: function (name = undefined) {
			if (typeof name === "string") return _status.gameInfomation[name]
			else if (typeof name === "number") {
				const list = [_status.gameInfomation.killNum, _status.gameInfomation.huanhundan, _status.gameInfomation.version, _status.gameInfomation.newversion]
				if (name < list.length) return list[name]
				else return undefined
			}
			return _status.gameInfomation
		},
		rawAttitude: function (from, to) {
				var x = 0,
					num = 0,
					temp,
					i;
				if (_status.ai.customAttitude) {
					for (i = 0; i < _status.ai.customAttitude.length; i++) {
						temp = _status.ai.customAttitude[i](from, to);
						if (temp != undefined) {
							x += temp;
							num++;
						}
					}
				}
				if (num) {
					return x / num;
				}
				if (_status.mode == "purple") {
					var real = get.realAttitude(from, to);
					if (from == to || to.identityShown || (from.storage.zhibi && from.storage.zhibi.includes(to)) || (_status.yeconfirm && ["rYe", "bYe"].includes(to.identity) && ["rYe", "bYe"].includes(to.identity))) return real * 1.1;
					return (to.ai.shown + 0.1) * real + (from.identity.slice(0, 1) == to.identity.slice(0, 1) ? 3 : -3) * (1 - to.ai.shown);
				} else if (_status.mode == "stratagem") {
					var x = 0,
						num = 0,
						temp,
						i;
					if (_status.ai.customAttitude) {
						for (i = 0; i < _status.ai.customAttitude.length; i++) {
							temp = _status.ai.customAttitude[i](from, to);
							if (temp != undefined) {
								x += temp;
								num++;
							}
						}
					}
					if (num) {
						return x / num;
					}
					var real = get.realAttitude(from, to),
						zhibi = from.storage.zhibi,
						stratagem_expose = from.storage.stratagem_expose,
						followCamouflage = true;
					if (to.ai.shown) return to.ai.shown * (real + (from.identity == to.identity || (from.identity == "zhu" && to.identity == "zhong") || (from.identity == "zhong" && to.identity == "zhu") || (from.identity == "nei" && to.identity == "zhu" && get.situation() <= 1) || (to.identity == "nei" && get.situation() <= 0 && ["zhu", "zhong"].includes(from.identity)) || (get.situation() >= 3 && from.identity == "fan") ? 2.9 : -2.9));
					if (from == to || to.identityShown || (((stratagem_expose && stratagem_expose.includes(to)) || (zhibi && zhibi.includes(to))) && !to.ai.stratagemCamouflage)) return real * 1.1;
					if (from.identity == "nei" && to.ai.stratagemCamouflage) return real * 1.1;
					if (to.identity == "nei") {
						if (from.identity == "fan") {
							if (get.population("zhong") == 0) {
								if (zhibi) {
									var dead = game.dead.slice();
									for (var current of dead) {
										if (from.storage.zhibi.includes(current) && current.ai.stratagemCamouflage) {
											if (from.storage.stratagem_expose && from.storage.stratagem_expose.includes(to)) return -7;
										}
									}
									if (zhibi.includes(to)) return 3;
								}
							}
						}
					}
					if (
						to.identity == "fan" &&
						from.identity == "nei" &&
						zhibi.includes(game.zhu) &&
						game.players
							.filter(i => i != from && !zhibi.includes(i))
							.map(i => i.identity)
							.reduce((p, c) => (!p.includes(c) ? p.push(c) && p : p), []).length == 1
					)
						return real;
					for (var fan of game.dead) {
						if (fan.identity != "fan" || !fan.storage.stratagem_revitalization) continue;
						for (var current of fan.storage.stratagem_expose) {
							if (to == current) {
								return real;
							}
						}
					}
					if (from.identity == "fan" && to.identity == "fan") {
						if (from.ai.stratagemCamouflage) {
							var zhu = game.zhu && game.zhu.isZhu && game.zhu.identityShown ? game.zhu : undefined;
							if (zhu) {
								if (zhu.storage.stratagem_expose && zhu.storage.stratagem_expose.includes(to)) return 0;
							}
							if (zhibi && zhibi.includes(to)) return -7;
						}
						if (to.ai.stratagemCamouflage) {
							var zhu = game.zhu && game.zhu.isZhu && game.zhu.identityShown ? game.zhu : undefined;
							if (zhu) {
								if (zhu.storage.stratagem_expose && zhu.storage.stratagem_expose.includes(to)) return 0;
							}
							if (zhibi && zhibi.includes(to)) return -7;
						}
					}
					if (from.identity != "nei" && zhibi && zhibi.includes(to) && !to.identityShown && followCamouflage && to.ai.stratagemCamouflage) return -5;
					if (from.identity != "nei" && stratagem_expose && stratagem_expose.includes(to) && !to.identityShown) return -5;
					if (zhibi) {
						for (var to2 of zhibi) {
							if (to2.storage.stratagem_expose) {
								if (to2.ai.stratagemCamouflage) {
									for (var to3 of to2.storage.stratagem_expose) {
										if (zhibi.slice().addArray(stratagem_expose).includes(to3)) {
											if (to == to2) {
												return real;
											}
										} else if (to == to3) {
											return Math.abs(real + 10) / 10;
										}
									}
								} else {
									for (var to3 of to2.storage.stratagem_expose) {
										if (!zhibi.slice().addArray(stratagem_expose).includes(to3) && to == to3) {
											return get.rawAttitude(to3, to) * Math.sign(real);
										}
									}
								}
							}
						}
					}
					return Math.max(-1, Math.min(-0.1, (-Math.min(5, to.countCards("hes") / 2 + 1) / 5 - Math.max(0, 5 - to.hp) / 4) / 2));
				}
				//正常身份模式态度
				var difficulty = 0;
				if (to == game.me) difficulty = 2 - get.difficulty();
				if (from == to || to.identityShown || from.storage.dongcha == to || to.identityShown || (from.storage.zhibi && from.storage.zhibi.includes(to))) {
					return get.realAttitude(from, to) + difficulty * 1.5;
				} else {
					if (from.identity == "zhong" && to.ai.shown == 0 && from.ai.tempIgnore && !from.ai.tempIgnore.includes(to)) {
						for (var i = 0; i < game.players.length; i++) {
							if (game.players[i].ai.shown == 0 && game.players[i].identity == "fan") {
								return -0.1 + difficulty * 1.5;
							}
						}
					}
					var aishown = to.ai.shown;
					if ((to.identity == "nei" || to.identity == "commoner") && to.ai.shown < 1 && (to.ai.identity_mark == "fan" || to.ai.identity_mark == "zhong")) {
						aishown = 0.5;
					} else if (aishown == 0 && to.identity != "fan" && to.identity != "zhu") {
						var fanshown = true;
						for (var i = 0; i < game.players.length; i++) {
							if (game.players[i].identity == "fan" && game.players[i].ai.shown == 0 && game.players[i] != from) {
								fanshown = false;
								break;
							}
						}
						if (fanshown) aishown = 0.3;
					}
					return get.realAttitude(from, to) * aishown + difficulty * 1.5;
				}
			},
		realAttitude: function (from, to) {
			if (_status.mode == "purple") {
				if (["rZhu", "rZhong", "bNei"].includes(from.identity)) {
					if (to.identity == "rZhu") return 8;
					if (["rZhong", "bNei"].includes(to.identity)) return 7;
					return -7;
				} else if (["bZhu", "bZhong", "rNei"].includes(from.identity)) {
					if (to.identity == "bZhu") return 8;
					if (["bZhong", "rNei"].includes(to.identity)) return 7;
					return -7;
				} else {
					if (["rYe", "bYe"].includes(to.identity)) return 7;
					if (
						["rZhu", "bZhu"].includes(to.identity) &&
						game.hasPlayer(function (current) {
							return ["rZhong", "bZhong", "rNei", "bNei"].includes(current.identity);
						})
					)
						return 6.5;
					return -7;
				}
			} else if (_status.mode == "stratagem") {
				if (!game.zhu) {
					if (from.identity == "nei" || to.identity == "nei") return -1;
					if (from.identity == to.identity) return 6;
					return -6;
				}
				var situation = get.situation();
				var identity = from.identity;
				var identity2 = to.identity;
				if (identity2 == "zhu" && !to.isZhu) {
					identity2 = "zhong";
					if (from == to) return 10;
				}
				if (from != to && to.identity == "nei" && to.ai.shown < 1 && (to.ai.identity_mark == "fan" || to.ai.identity_mark == "zhong")) {
					identity2 = to.ai.identity_mark;
				}
				if (from.identity != "nei" && from != to && get.population("fan") == 0 && identity2 == "zhong") {
					for (var i = 0; i < game.players.length; i++) {
						if (game.players[i].identity == "nei" && game.players[i].ai.identity_mark == "zhong" && game.players[i].ai.shown < 1) {
							identity2 = "nei";
							break;
						}
					}
				}
				switch (identity) {
					case "zhu":
						switch (identity2) {
							case "zhu":
								return 10;
							case "zhong":
								return 6;
							case "nei":
								if (game.players.length == 2) return -10;
								if (to.identity == "zhong") return 0;
								if (get.population("fan") == 0) {
									if (to.ai.identity_mark == "zhong" && to.ai.shown < 1) return 0;
									return -1;
								}
								if (get.population("fan") == 1 && get.population("nei") == 1 && game.players.length == 3) {
									var fan;
									for (var i = 0; i < game.players.length; i++) {
										if (game.players[i].identity == "fan") {
											fan = game.players[i];
											break;
										}
									}
									if (fan) {
										if (to.hp > 1 && to.hp > fan.hp && to.countCards("he") > fan.countCards("he")) {
											return -3;
										}
									}
									return 0;
								}
								if (situation > 1) return Math.max((situation - 8) / 3, -2);
								return Math.min(3, get.population("fan"));
							case "fan":
								if (get.population("fan") == 1 && get.population("nei") == 1 && game.players.length == 3) {
									var nei;
									for (var i = 0; i < game.players.length; i++) {
										if (game.players[i].identity == "nei") {
											nei = game.players[i];
											break;
										}
									}
									if (nei) {
										if (nei.hp > 1 && nei.hp > to.hp && nei.countCards("he") > to.countCards("he")) {
											return 0;
										}
									}
									return -3;
								}
								return -4;
						}
						break;
					case "zhong":
						switch (identity2) {
							case "zhu":
								return 10;
							case "zhong":
								if (from == to) return 5;
								if (get.population("zhong") > 1) return 3;
								return 4;
							case "nei":
								if (get.population("fan") == 0 && get.population("zhong") == 1) return -2;
								if (get.population("zhong") >= 1) return Math.min(3, -situation);
								return 3;
							case "fan":
								return -8;
						}
						break;
					case "nei":
						if (identity2 == "zhu" && game.players.length == 2) return -10;
						if (from != to && identity2 != "zhu" && game.players.length == 3) return -8;
						var strategy = get.aiStrategy();
						if (strategy == 4) {
							if (from == to) return 10;
							return 0;
						}
						var num;
						switch (identity2) {
							case "zhu":
								if (strategy == 6) return -1;
								if (strategy == 5) return 10;
								if (to.hp <= 0) return 10;
								if (get.population("fan") == 1) {
									var fan;
									for (var i = 0; i < game.players.length; i++) {
										if (game.players[i].identity == "fan") {
											fan = game.players[i];
											break;
										}
									}
									if (fan) {
										if (to.hp > 1 && to.hp > fan.hp && to.countCards("he") > fan.countCards("he")) {
											return -3;
										}
									}
									return 0;
								} else {
									if (situation > 1 || get.population("fan") == 0) num = 0;
									else num = get.population("fan") + Math.max(0, 3 - game.zhu.hp);
								}
								if (strategy == 2) num--;
								if (strategy == 3) num++;
								return num;
							case "zhong":
								if (strategy == 5) return Math.min(0, -situation);
								if (strategy == 6) return Math.max(-1, -situation);
								if (get.population("fan") == 0) num = -5;
								else if (situation <= 0) num = 0;
								else if (game.zhu && game.zhu.hp < 2) num = 0;
								else if (game.zhu && game.zhu.hp == 2) num = -1;
								else if (game.zhu && game.zhu.hp <= 2 && situation > 1) num = -1;
								else num = -2;
								if (strategy == 2) num--;
								if (strategy == 3) num++;
								return num;
							case "nei":
								if (from == to) return 10;
								if (from.ai.friend.includes(to)) return 5;
								if (get.population("fan") + get.population("zhong") > 0) return 0;
								return -5;
							case "fan":
								if (strategy == 5) return Math.max(-1, situation);
								if (strategy == 6) return Math.min(0, situation);
								if ((game.zhu && game.zhu.hp <= 2 && situation < 0) || situation < -1) num = -3;
								else if (situation < 0 || get.population("zhong") == 0) num = -2;
								else if ((game.zhu && game.zhu.hp >= 4 && situation > 0) || situation > 1) num = 1;
								else num = 0;
								if (strategy == 2) num++;
								if (strategy == 3) num--;
								return num;
						}
						break;
					case "fan":
						switch (identity2) {
							case "zhu":
								if (get.population("nei") > 0) {
									if (situation == 1) return -6;
									if (situation > 1) return -5;
								}
								return -8;
							case "zhong":
								if (game.zhu.hp >= 3 && to.hp == 1) {
									return -10;
								}
								return -7;
							case "nei":
								if (get.population("fan") == 1) return 0;
								if (get.population("zhong") == 0) return -2;
								if (game.zhu && game.zhu.hp <= 2 && game.zhu.identityShown) return -1;
								return 3;
							case "fan":
								return 5;
						}
				}
			}
			//正常身份模式态度
			if (!game.zhu) {
				if (from.identity == "nei" || to.identity == "nei" || from.identity == "commoner" || to.identity == "commoner") return -1;
				if (from.identity == to.identity) return 6;
				return -6;
			}
			var situation = get.situation();
			var identity = from.identity;
			var identity2 = to.identity;
			if (identity2 == "zhu" && !to.isZhu) {
				identity2 = "zhong";
				if (from == to) return 10;
			}
			if (from != to && to.identity == "nei" && to.ai.shown < 1 && (to.ai.identity_mark == "fan" || to.ai.identity_mark == "zhong")) {
				identity2 = to.ai.identity_mark;
			}
			if (from.identity != "nei" && from.identity != "commoner" && from != to && get.population("fan") == 0 && identity2 == "zhong") {
				for (var i = 0; i < game.players.length; i++) {
					if (game.players[i].identity == "nei" && game.players[i].ai.identity_mark == "zhong" && game.players[i].ai.shown < 1) {
						identity2 = "nei";
						break;
					} else if (game.players[i].identity == "commoner" && game.players[i].ai.identity_mark == "zhong" && game.players[i].ai.shown < 1) {
						identity2 = "commoner";
						break;
					}
				}
			}
			var zhongmode = false;
			if (!game.zhu.isZhu) {
				zhongmode = true;
			}
			switch (identity) {
				case "zhu":
					switch (identity2) {
						case "zhu":
							return 10;
						case "zhong":
						case "mingzhong":
							return 6;
						case "nei":
							if (game.players.length == 2) return -10;
							if (to.identity == "zhong") return 0;
							if (get.population("fan") == 0) {
								if (to.ai.identity_mark == "zhong" && to.ai.shown < 1) return 0;
								return -0.5;
							}
							if (zhongmode && to.ai.sizhong && to.ai.shown < 1) return 6;
							if (get.population("fan") == 1 && get.population("nei") == 1 && game.players.length == 3) {
								var fan;
								for (var i = 0; i < game.players.length; i++) {
									if (game.players[i].identity == "fan") {
										fan = game.players[i];
										break;
									}
								}
								if (fan) {
									if (to.hp > 1 && to.hp > fan.hp && to.countCards("he") > fan.countCards("he")) {
										return -3;
									}
								}
								return 0;
							}
							if (situation > 1) return 0;
							return Math.min(3, get.population("fan"));
						case "fan":
							if (get.population("fan") == 1 && get.population("nei") == 1 && game.players.length == 3) {
								var nei;
								for (var i = 0; i < game.players.length; i++) {
									if (game.players[i].identity == "nei") {
										nei = game.players[i];
										break;
									}
								}
								if (nei) {
									if (nei.hp > 1 && nei.hp > to.hp && nei.countCards("he") > to.countCards("he")) {
										return 0;
									}
								}
								return -3;
							}
							return -4;
						case "commoner":
							if (to.identity == "zhong") return 0;
							if (get.population("fan") == 0) {
								if (to.ai.identity_mark == "zhong" && to.ai.shown < 1) return 0;
								return -0.5;
							}
							if (zhongmode && to.ai.sizhong && to.ai.shown < 1) return 6;
							if (game.players.length == 3) {
								var fan;
								for (var i = 0; i < game.players.length; i++) {
									if (game.players[i].identity == "fan") {
										fan = game.players[i];
										break;
									}
								}
								if (fan) {
									if (to.hp > 1 && to.hp > fan.hp && to.countCards("he") > fan.countCards("he")) {
										return -3;
									}
								}
								return 3;
							}
							if (situation < 0 && game.zhu && game.zhu.hp <= 2) return -3.8;
							return Math.max(-4, 2 - get.population("fan"));
					}
					break;
				case "zhong":
				case "mingzhong":
					switch (identity2) {
						case "zhu":
							return 10;
						case "zhong":
						case "mingzhong":
							return 4;
						case "nei":
							if (get.population("fan") == 0) return -2;
							if (zhongmode && to.ai.sizhong && to.ai.shown < 1) return 6;
							return Math.min(3, -situation);
						case "fan":
							return -8;
						case "commoner":
							return Math.min(3, Math.max(-3, situation - 0.2));
					}
					break;
				case "nei":
					if (identity2 == "zhu" && game.players.length == 2) return -10;
					if (from != to && identity2 != "zhu" && identity2 != "commoner" && game.players.length == 3) return -8;
					var strategy = get.aiStrategy();
					if (strategy == 4) {
						if (from == to) return 10;
						return 0;
					}
					var num;
					switch (identity2) {
						case "zhu":
							if (strategy == 6) return -1;
							if (strategy == 5) return 10;
							if (to.hp <= 0) return 10;
							if (get.population("fan") == 1) {
								var fan;
								for (var i = 0; i < game.players.length; i++) {
									if (game.players[i].identity == "fan") {
										fan = game.players[i];
										break;
									}
								}
								if (fan) {
									if (to.hp > 1 && to.hp > fan.hp && to.countCards("he") > fan.countCards("he")) {
										return -1.7;
									}
								}
								return 0;
							} else {
								if (situation > 1 || get.population("fan") == 0) num = 0;
								else num = get.population("fan") + Math.max(0, 3 - game.zhu.hp);
							}
							if (strategy == 2) num--;
							if (strategy == 3) num++;
							return num;
						case "zhong":
							if (strategy == 5) return Math.min(0, -situation);
							if (strategy == 6) return Math.max(-1, -situation);
							if (get.population("fan") == 0) num = -5;
							else if (situation <= 0) num = 0;
							else if (game.zhu && game.zhu.hp < 2) num = 0;
							else if (game.zhu && game.zhu.hp == 2) num = -1;
							else if (game.zhu && game.zhu.hp <= 2 && situation > 1) num = -1;
							else num = -2;
							if (zhongmode && situation < 2) {
								num = 4;
							}
							if (strategy == 2) num--;
							if (strategy == 3) num++;
							return num;
						case "mingzhong":
							if (zhongmode) {
								if (from.ai.sizhong == undefined) {
									from.ai.sizhong = Math.random() < 0.5;
								}
								if (from.ai.sizhong) return 6;
							}
							if (strategy == 5) return Math.min(0, -situation);
							if (strategy == 6) return Math.max(-1, -situation);
							if (get.population("fan") == 0) num = -5;
							else if (situation <= 0) num = 0;
							else num = -3;
							if (strategy == 2) num--;
							if (strategy == 3) num++;
							return num;
						case "nei":
							if (from == to) return 10;
							if (from.ai.friend.includes(to)) return 5;
							if (get.population("fan") + get.population("zhong") > 0) return 0;
							return -5;
						case "fan":
							if (strategy == 5) return Math.max(-1, situation);
							if (strategy == 6) return Math.min(0, situation);
							if ((game.zhu && game.zhu.hp <= 2 && situation < 0) || situation < -1) num = -3;
							else if (situation < 0 || get.population("zhong") + get.population("mingzhong") == 0) num = -2;
							else if ((game.zhu && game.zhu.hp >= 4 && situation > 0) || situation > 1) num = 1;
							else num = 0;
							if (strategy == 2) num++;
							if (strategy == 3) num--;
							return num;
						case "commoner":
							if (game.players.length <= 4) return 5;
							return Math.min(Math.max(-situation, -2), 2);
					}
					break;
				case "fan":
					switch (identity2) {
						case "zhu":
							if (get.population("nei") > 0) {
								if (situation == 1) return -6;
								if (situation > 1) return -5;
							}
							return -8;
						case "zhong":
							if (!zhongmode && game.zhu.hp >= 3 && to.hp == 1) {
								return -10;
							}
							return -7;
						case "mingzhong":
							return -5;
						case "nei":
							if (zhongmode && to.ai.sizhong) return -7;
							if (get.population("fan") == 1) return 0;
							if (get.population("zhong") + get.population("mingzhong") == 0) return -7;
							if (game.zhu && game.zhu.hp <= 2) return -1;
							return Math.min(3, situation);
						case "fan":
							return 5;
						case "commoner":
							return 2 * get.population("fan") - 3;
					}
					break;
				case "commoner":
					switch (identity2) {
						case "zhu":
							if (situation > 0) return 2 * Math.min(4, to.hp + to.countCards("h") / 4 - 2);
							if (situation >= -3 && game.zhu) return to.hp - 2 + to.countCards("h") / 4; //return Math.min(-0.1,5-game.zhu.hp);
							return to.hp + to.countCards("h") / 3 - 4;
						case "zhong":
							if (situation > 0) {
								if (to.hp >= 2) return Math.min(3, Math.max(1, to.hp + to.countCards("h") / 4 - 4));
								else return 0;
							}
							return -2;
						case "nei":
							if (game.players.length == 3 && get.population("nei") == 1) return Math.min(3.5, to.hp - 1.5 + to.countCards("h") / 3) - (to.hp < (game.zhu ? game.zhu.hp : 0) ? 4 : 0);
							if (game.players.length <= 4 && get.population("nei") == 1) return Math.min(5, to.hp - 1.5 + to.countCards("h") / 3);
							if (situation > 0) return -3;
							return 0;
						case "fan":
							if (situation < 0) return to.hp + to.countCards("h") / 4 - 1.7 * get.population("fan") + 2;
							else if (situation == 0) return 0;
							return 0.55 * get.population("fan") - 2.1;
						case "commoner":
							return from == to ? 10 : to.hp <= 2 ? -2 : 0;
					}
					break;
			}
		},
		situation: function (absolute) {
			var i, j, player;
			var zhuzhong = 0,
				total = 0,
				zhu,
				fan = 0;
			for (i = 0; i < game.players.length; i++) {
				player = game.players[i];
				var php = player.hp;
				if (player.hasSkill("benghuai") && php > 4) {
					php = 4;
				} else if (php > 6) {
					php = 6;
				}
				j = player.countCards("h") + player.countCards("e") * 1.5 + php * 2;
				if (player.identity == "zhu") {
					zhuzhong += j * 1.2 + 5;
					total += j * 1.2 + 5;
					zhu = j;
				} else if (player.identity == "zhong" || player.identity == "mingzhong") {
					zhuzhong += j * 0.8 + 3;
					total += j * 0.8 + 3;
				} else if (player.identity == "fan") {
					zhuzhong -= j + 4;
					total += j + 4;
					fan += j + 4;
				}
			}
			if (absolute) return zhuzhong;
			var result = parseInt(10 * Math.abs(zhuzhong / total));
			if (zhuzhong < 0) result = -result;
			if (!game.zhong) {
				if (zhu < 12 && fan > 30) result--;
				if (zhu < 6 && fan > 15) result--;
				if (zhu < 4) result--;
			}
			return result;
		},
		insightResult: function (from, to) {
			var friend = "friend",
				enemy = "enemy";
			if (from.identity == "nei") return to.identity;
			if (to.identity == "nei") return friend;
			if (from.ai.stratagemCamouflage || to.ai.stratagemCamouflage) return enemy;
			if (from.identity == to.identity || (from.identity == "zhu" && to.identity == "zhong") || (from.identity == "zhong" && to.identity == "zhu")) return friend;
			return enemy;
		},
	},
	character: MAIN.character,
	skill: MAIN.skill,
	translate: MAIN.translate,
	dynamicTranslate: MAIN.dynamicTranslate,
	card: MAIN.card,
	characterTitle: MAIN.characterTitle,
	help: {

	},
};

export default () => {
	return langrensha
}
